﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XSTDZ.ERP.WebApp.Models.Ado;
using XSTDZ.ERP.WebApp.Models;

namespace XSTDZ.ERP.WebApp.Controllers
{
    /// <summary>
    /// 报表控制器
    /// </summary>
    public class ReportsController : Controller
    {
        private readonly ReportQuery reportQuery = new ReportQuery();
        private readonly ExportToExcelModel export = new ExportToExcelModel();
        #region 发货统计 ( 老厂,新厂,成都 )
        #region 不同的地区对应不同的View
        //发货统计(老厂)
        public ActionResult SendProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.LaoChangCode;
            return View();
        }
        //发货统计(新厂)
        public ActionResult XCSendProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.XinChangCode;
            return View("SendProduct");
        }
        //发货统计(新厂)
        public ActionResult CDSendProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View("SendProduct");
        }
        #endregion
        
        //发货统计(获取数据)
        public ActionResult SendProductData()
        {
            return Content(reportQuery.SendProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult ExportToExcel()
        {
            string[] fileds = new string[] { "发货单号", "产品名称", "编码", "规格", "发货数量", "发货单位", "发货人", "发货时间", "送货人", "收货单位", "提交人", "提交时间", "确认状态", "确认人", "确认时间" };
            export.CreateDataToExcel(this.HttpContext, "发货统计", fileds, reportQuery.SendProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 收退货统计 ( 老厂,新厂,成都 )
        #region 收退货统计按地区
        //收退货统计(老厂)
        public ActionResult TakeReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.LaoChangCode;
            return View();
        }
        //收退货统计(新厂)
        public ActionResult XCTakeReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.XinChangCode;
            return View("TakeReturnProduct");
        }
        //收退货统计(成都)
        public ActionResult CDTakeReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View("TakeReturnProduct");
        }
        #endregion
        //收退货统计(获取数据)
        public ActionResult TakeReturnProductData()
        {
            return Content(reportQuery.TakeReturnProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult TakeReturnProductToExcel()
        {
            string[] fileds = new string[] { "退货单号", "产品名称", "编码", "规格", "退货数量", "退货单位", "退货人", "退货时间", "送货人", "收货单位", "提交人", "提交时间", "确认状态", "确认人", "确认时间" };
            export.CreateDataToExcel(this.HttpContext, "收退货统计", fileds, reportQuery.TakeReturnProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 收货统计 ( 成都,深圳 )

        #region 收货统计按地区
        //收货统计(成都)
        public ActionResult TakeProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //收货统计(深圳)
        public ActionResult SZTakeProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("TakeProduct");
        }
        #endregion
        //收货统计(获取数据)
        public ActionResult TakeProductData()
        {
            return Content(reportQuery.TakeProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult TakeProductToExcel()
        {
            string[] fileds = new string[] { "发货单号", "产品名称", "编码", "规格", "发货数量", "发货单位", "发货人", "发货时间", "送货人", "收货单位", "提交人", "提交时间", "确认状态", "确认人", "确认时间" };
            export.CreateDataToExcel(this.HttpContext, "收货统计", fileds, reportQuery.TakeProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 入库统计 ( 成都,深圳 )

        #region 入库统计按地区
        //入库统计(成都)
        public ActionResult InStockProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //入库统计(深圳)
        public ActionResult SZInStockProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("InStockProduct");
        }
        #endregion
        //入库统计(获取数据)
        public ActionResult InStockProductData()
        {
            return Content(reportQuery.InStockProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult InStockProductToExcel()
        {
            string[] fileds = new string[] { "入库单号", "产品名称", "编码", "规格", "入库数量", "入库单位", "入库人", "入库时间", "送货人", "发货单位", "提交人", "提交时间" };
            export.CreateDataToExcel(this.HttpContext, "入库统计", fileds, reportQuery.InStockProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 销售统计 ( 成都,深圳 )
      
        #region 销售统计按地区
        //销售统计(成都)
        public ActionResult SellProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //销售统计(深圳)
        public ActionResult SZSellProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("SellProduct");
        }
        #endregion
        //销售统计(获取数据)
        public ActionResult SellProductData()
        {
            return Content(reportQuery.SellProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult SellProductToExcel()
        {
            string[] fileds = new string[] { "销售单号", "客户订单号", "产品名称", "编码", "规格", "销售数量", "销售单价", "销售单位", "销售人", "销售时间", "送货人", "购买单位", "是否开票", "提交人", "提交时间", "审核状态", "审核人", "审核时间" };
            export.CreateDataToExcel(this.HttpContext, "销售统计", fileds, reportQuery.SellProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 销售退货统计 ( 成都,深圳 )
     
        #region 销售退货统计按地区
        //销售退货统计(成都)
        public ActionResult SellReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //销售退货统计(深圳)
        public ActionResult SZSellReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("SellReturnProduct");
        }
        #endregion
        //销售退货统计(获取数据)
        public ActionResult SellReturnProductData()
        {
            return Content(reportQuery.SellReturnProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult SellReturnProductToExcel()
        {
            string[] fileds = new string[] { "退货单号", "产品名称", "编码", "规格", "退货数量", "退货单价", "受理单位", "受理人", "受理时间", "退货单位", "提交人", "提交时间", "审核状态", "审核人", "审核时间" };
            export.CreateDataToExcel(this.HttpContext, "销售退货统计", fileds, reportQuery.SellReturnProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 退货厂里统计 ( 成都,深圳 )
       
        #region 退货厂里统计按地区
        //退货厂里统计(成都)
        public ActionResult SendReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //退货厂里统计(深圳)
        public ActionResult SZSendReturnProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("SendReturnProduct");
        }
        #endregion
        //退货厂里统计(获取数据)
        public ActionResult SendReturnProductData()
        {
            return Content(reportQuery.SendReturnProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult SendReturnProductToExcel()
        {
            string[] fileds = new string[] { "退货单号", "产品名称", "编码", "规格", "退货数量", "退货单位", "退货人", "退货时间", "送货人", "收货单位", "提交人", "提交时间", "确认状态", "确认人", "确认时间" };
            export.CreateDataToExcel(this.HttpContext, "收退货统计", fileds, reportQuery.SendReturnProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 损溢统计 ( 成都,深圳 )
        
        #region 损溢统计按地区
        //损溢统计(成都)
        public ActionResult ProfitAndLossProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //损溢统计(深圳)
        public ActionResult SZProfitAndLossProduct()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("ProfitAndLossProduct");
        }
        #endregion
        //损溢统计(获取数据)
        public ActionResult ProfitAndLossProductData()
        {
            return Content(reportQuery.ProfitAndLossProduct(this.HttpContext));
        }
        //导出到Excel
        public ActionResult ProfitAndLossProductToExcel()
        {
            string[] fileds = new string[] { "盈亏单号", "产品名称", "编码", "规格", "盈亏数量", "所属单位", "提交人", "提交时间", "确认状态", "确认人", "确认时间" };
            export.CreateDataToExcel(this.HttpContext, "损溢统计", fileds, reportQuery.ProfitAndLossProductData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 销售收款情况（明细） ( 成都,深圳 )

        #region 销售收款情况（明细）按地区
        //销售收款情况（明细）(成都)
        public ActionResult ReceivablePayableSell()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //销售收款情况（明细）(深圳)
        public ActionResult SZReceivablePayableSell()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("ReceivablePayableSell");
        }
        #endregion
        //销售收款情况（明细）(获取数据)
        public ActionResult ReceivablePayableSellData()
        {
            return Content(reportQuery.ReceivablePayableSell(this.HttpContext));
        }
        //导出到Excel
        public ActionResult ReceivablePayableSellToExcel()
        {
            string[] fileds = new string[] { "销售单号", "客户名称", "应收金额", "已收金额", "优惠金额", "所属单位", "负责人", "产单时间"};
            export.CreateDataToExcel(this.HttpContext, "销售收款情况（明细）", fileds, reportQuery.ReceivablePayableSellData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 销售退款情况（明细） ( 成都,深圳 )

        #region 销售退款情况（明细按地区
        //销售退款情况（明细）(成都)
        public ActionResult ReceivablePayableSellReturn()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode;
            return View();
        }
        //销售退款情况（明细）(深圳)
        public ActionResult SZReceivablePayableSellReturn()
        {
            ViewBag.OrgCode = XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode;
            return View("ReceivablePayableSellReturn");
        }
        #endregion
        //销售退款情况（明细）(获取数据)
        public ActionResult ReceivablePayableSellReturnData()
        {
            return Content(reportQuery.ReceivablePayableSellReturn(this.HttpContext));
        }
        //导出到Excel
        public ActionResult ReceivablePayableSellReturnToExcel()
        {
            string[] fileds = new string[] { "退货单号", "客户名称", "应退金额", "已退金额", "优惠金额", "所属单位", "负责人", "产单时间" };
            export.CreateDataToExcel(this.HttpContext, "销售退款情况（明细）", fileds, reportQuery.ReceivablePayableSellReturnData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 调拨收款情况（明细） ( 成都 )
        //调拨收款情况（明细）
        public ActionResult ReceivablePayableAllotShou()
        {
            return View();
        }
        //调拨收款情况（明细）(获取数据)
        public ActionResult ReceivablePayableAllotShouData()
        {
            return Content(reportQuery.ReceivablePayableAllotShou(this.HttpContext));
        }
        //导出到Excel
    public ActionResult ReceivablePayableAllotShouToExcel()
        {
            string[] fileds = new string[] { "调拨单号", "客户名称", "应收金额", "已收金额", "优惠金额", "所属单位", "负责人", "产单时间" };
            export.CreateDataToExcel(this.HttpContext, "调拨收款情况（明细）", fileds, reportQuery.ReceivablePayableAllotShouData(this.HttpContext));
            return Content("");
        }
        #endregion
        #region 调拨付款情况（明细） ( 成都 )
        //调拨付款情况（明细）
        public ActionResult ReceivablePayableAllotFu()
        {
            return View();
        }
        //调拨付款情况（明细）(获取数据)
        public ActionResult ReceivablePayableAllotFuData()
        {
            return Content(reportQuery.ReceivablePayableAllotFu(this.HttpContext));
        }
        //导出到Excel
        public ActionResult ReceivablePayableAllotFuToExcel()
        {
            string[] fileds = new string[] { "调拨单号", "客户名称", "应收金额", "已付金额", "优惠金额", "所属单位", "负责人", "产单时间" };
            export.CreateDataToExcel(this.HttpContext, "调拨付款情况（明细）", fileds, reportQuery.ReceivablePayableAllotFuData(this.HttpContext));
            return Content("");
        }
        #endregion
    }
}
